package com.lbmb.mdps.settings.service.impl;

import com.lbmb.mdps.commons.exception.AdministratorException;
import com.lbmb.mdps.settings.dao.AdministratorDao;
import com.lbmb.mdps.settings.domain.Administrator;
import com.lbmb.mdps.settings.service.AdministratorService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author 林文塨
 * @date 2022-05-30 2:36
 * description
 */
@Service("administratorService")
public class AdministratorServiceImpl implements AdministratorService {

    @Resource
    private AdministratorDao administratorDao;

    @Override
    public Administrator login(Administrator administrator) throws AdministratorException {

        /*
         * 管理员登陆
         * @author 林文塨
         * @date 2022/5/30 9:13
         * @param [administrator]
         * @return com.lbmb.mdps.settings.domain.Administrator
         */
        Administrator administratorVo = administratorDao.login(administrator);

        if (administratorVo == null) {
            throw new AdministratorException("账号或者密码错误");
        }

        return administratorVo;
    }

    @Override
    public Administrator getAdministratorById(Long currentUserId) throws AdministratorException {
        /*
         * 根据id查找单个管理员
         * @author 林文塨
         * @date 2022/5/31 22:43
         * @param [currentUserId]
         * @return com.lbmb.mdps.settings.domain.Administrator
         */

        Administrator administrator = administratorDao.getAdministratorById(currentUserId);

        if (administrator == null) {
            throw new AdministratorException("查找当前登录管理员失败！");
        }

        return administrator;
    }

    @Override
    public Boolean getPrivilege(Long currentUserId) {
        /*
         * 判断当前登录是否为管理员
         * @author 林文塨
         * @date 2022/5/31 22:52
         * @param [currentUserId]
         * @return java.lang.Boolean
         */
        Administrator administrator = administratorDao.getAdministratorById(currentUserId);

        return administrator != null;
    }
}
